home *** CD-ROM | disk | FTP | other *** search
/ Power CD / Power CD ATARI-Rechner Lieben.iso / UTILITY / LSRC_222 / LHA5.S < prev    next >
Encoding:
Text File  |  1993-07-21  |  32.5 KB  |  843 lines

  1.  
  2.             export position
  3.             export prev
  4.             export next
  5.             export parent
  6.             export childcount
  7.             export text
  8.             export encode5
  9.             export init_encode5
  10.             export output5
  11.             export insert_node
  12.             export get_next_match
  13.             export in_split
  14.             export output_pos
  15.             export output_mask
  16.             import buf
  17.             import c_freq
  18.             import p_freq
  19.             import level
  20.             import infile
  21.             import blocksize
  22.             import buffered
  23.             import send_block
  24.             import fread_crc
  25.             import start_huf
  26.             import end_huf
  27.             import ProcInd
  28.             import shipout
  29.  
  30.  BUFSIZ          set 16384
  31.  
  32.     MODULE encode5
  33.  
  34.         import remainder,pos,printcount,l_mpos
  35.         import  get_next_match
  36.         TEXT
  37.  
  38. ;encode5:
  39.             movem.l D3-D7/A2-A6,-(SP)
  40.             lea     pos(PC),A6      ; pos  GLOBAL!
  41.             move.l  infile(PC),A1   ; infile
  42.             move.w  #$2100,D0       ; DICSIZ+MAXMATCH
  43.             move.l  text(PC),A0     ; text
  44.             lea     $2000(A0),A0    ; text[DICSIZE]
  45.             bsr     fread_crc       ; fread_crc
  46.             move.w  D0,remainder-pos(a6)    ;+ remainder=fread_crcx
  47.             ext.l   d0
  48.             add.l   d0,printcount-pos(a6)
  49.             cmp.w   #$2000,d0
  50.             blt.s   ind2
  51. proc_ind2:  move.l  blocksize(pc),d0
  52.             cmp.l   printcount(pc),d0
  53.             bgt.s   enc51
  54.             sub.l   d0,printcount-pos(a6)
  55. ind2:       bsr     ProcInd
  56.             bra.s   proc_ind2
  57. enc51:;        move.w    #$FFFF,D0
  58.             and.l    D0,D1    
  59.             and.l    D0,D2
  60.             and.l    D0,D3    
  61.             and.l    D0,D4    
  62.             and.l    D0,D5    
  63.             and.l    D0,D6    
  64.             and.l    D0,D7    
  65.             
  66.             moveq   #0,d7           ; matchlen=0
  67.             moveq   #0,D0           ;+? 0
  68.             move.l  parent-pos(a6),a2;+
  69.             move.l  prev-pos(a6),a3 ;+
  70.             move.l  next-pos(a6),a4 ;+ a4 = next[] GLOBAL!
  71.             move.w  #$2000,(A6)     ; pos=DICSIZ
  72. ;            movem.w D4-d5,-(SP)     ;+
  73.             move.w  D4,-(SP)     ;+
  74.             bsr     insert_node     ; insert_node
  75. ;            movem.w (sp)+,D4-d5     ;+
  76.             move.w (sp)+,D4     ;+
  77.             bra.b   encod7          ; while
  78. ; --------------------------------------;
  79. encod1:     move.w  d7,D4           ; lastmatchlen=matchlen
  80. ;            move.w  d6,D5           ; lastmatchpos=matchpos
  81.             move.w  d6,l_mpos-pos(A6)   ; lastmatchpos=matchpos
  82.             bsr     get_next_match  ; get_next_match
  83.             cmp.w   remainder(PC),D7 ;+ if (matchlen>remainder)
  84.             ble.b   encod2
  85.             move.w  remainder(PC),d7 ;+ matchlen=remainder
  86. encod2:     cmp.w   d7,D4           ; if (matchlen>lastmatchlen
  87.             blt.b   encod3          ; ||
  88.             cmp.w   #3,D4           ; lastmatchlen<THRESHOLD)
  89.             bge.b   encod4
  90. encod3:     move.w  (A6),D0         ; pos
  91.             move.l text(PC),A0      ;+ text
  92.             moveq   #0,D1
  93.             move.b  -1(A0,D0.w),D1  ; text[pos-1]
  94.             moveq   #0,D3           ; 0
  95.             bsr     output5         ; output5(..)
  96.             bra.b   encod8
  97. ; --------------------------------------;
  98. encod4:     move.w  (A6),D3         ; pos
  99. ;            sub.w   D5,D3           ; pos-lastmatchpos
  100.             sub.w   l_mpos(PC),D3           ; pos-lastmatchpos
  101.             subq.w  #2,D3           ; pos-lastmatchpos-2
  102.             and.w   #$1FFF,D3       ; (pos-lastmatchpos-2)&(UCHAR_MAX+1-THRESHOLD)
  103.             move.w  D4,D1           ; lastmatchlen
  104.             add.w   #$FD,D1         ; lastmatchlen+UCHAR_MAX+1-THRESHOLD
  105.             bsr     output5         ; output5
  106.             subq.w  #1,D4           ;
  107.             ble.b   encod7          ; while (--lastmatchlen>0)
  108. encod5:     bsr     get_next_match  ;   get_next_match
  109.             subq.w  #1,D4           ;
  110.             bgt.b   encod5
  111. ; --------------------------------------;
  112. encod7:     cmp.w   remainder(PC),D7;+ if (matchlen>remainder)
  113.             ble.b   encod8          ;
  114.             move.w  remainder(PC),d7;+  matchlen=remainder
  115. ; --------------------------------------;
  116. encod8:     move.w  remainder(PC),D0;+ remainder
  117.             bgt.b   encod1          ; <0
  118. ; --------------------------------------;
  119.             bsr     end_huf         ; end_huf
  120.             tst.b   buffered
  121.             bne.b   encod11
  122.             bsr     shipout
  123.  
  124. encod11:    movem.l (SP)+,D3-D7/A2-A6
  125.             rts
  126.  
  127.     ENDMOD
  128.  
  129.             align
  130.  
  131.     MODULE output5  ;p.w in D3    c.w in D1
  132.  
  133.     IMPORT output_mask,output_pos,cpos
  134.  
  135.     TEXT
  136.             move.w  output_pos(pc),D0   ;+
  137.             move.l  buf(PC),A1          ;+
  138.             adda.l  D0,A1               ;.l?
  139.              subq.w    #1,output_mask-pos(A6)  
  140. ;            lsr.w   output_mask-pos(a6) ; output_mask >> 1
  141. ;            bne.b   out5_2              ; if {output_mask = 0) {
  142.             bpl.b   out5_2              ; if {output_mask = 0) {
  143. ;            move.w  #$80,output_mask-pos(a6) ; output_mask=1U <<(CHAR_BIT-1)
  144.             move.w  #7,output_mask-pos(a6) ; output_mask=1U <<(CHAR_BIT-1)
  145.             cmp.w   #BUFSIZ-$18,D0      ; -3*CHAR_BIT+bufsiz
  146.             bcs.b   out5_1              ;
  147.             move.w  d1,-(sp)            ;
  148.             bsr     send_block          ; send_block
  149.             moveq    #0,D1
  150.             moveq    #0,D2
  151.             move.w  (sp)+,d1            ;
  152.             move.l  buf(PC),A1          ;+
  153.             moveq   #0,D0               ;+ outputpos=0
  154.                                         ; D0=output_pos=0
  155. out5_1:     move.w  D0,cpos-pos(A6)     ; cpos=output_pos
  156.             clr.b   (A1)+               ; buf[cpos]=0
  157.             addq.w  #1,D0               ; output_pos++
  158. out5_2:     move.b  D1,(A1)+            ;+ buf[output_pos]=c
  159.             addq.w  #1,D0               ; output_pos++
  160.             add.w   D1,D1               ; c*2
  161.             lea     c_freq,A0              ; c_freq
  162.             addq.w  #1,0(A0,D1.w)       ; c_freq[c]++
  163.             cmp.w   #$0200,D1           ; if (c>=(1U<<CHAR_BIT)
  164.             bcs.b   out5_5              ;
  165. ;            move.b  output_mask+1-pos(a6),D1    ; output_mask
  166.             move.w  output_mask-pos(a6),D1    ; output_mask
  167. ;;;            moveq   #0,D2               ;
  168.             move.w  cpos(PC),D2         ; cpos
  169.             sub.w   D0,D2               ;
  170. ;            or.b    D1,0(A1,D2.w)       ;+ buf[cpos] != output_mask
  171.             bset.b    D1,0(A1,D2.w)       ;+ buf[cpos] != output_mask
  172.             move.w  D3,D1               ; p
  173.             lsr.w   #8,D1               ; p>>CHAR_BIT
  174.             move.b  D1,(A1)+            ; buf[output_pos++]=p>>CHAR_BIT
  175.             bne.b    nout_5_1            ;+ dann ...
  176.             move.b  D3,(A1)+            ;+ buf[output_pos++]=p
  177.             addq.w  #2,D0               ;+ output_pos++&++
  178.             moveq   #16,D1              ; *TT -> move.w d3,...*
  179.             tst.w   D3                  ;.W!!!!
  180.             dbeq    D1,out5_3           ;
  181.             bra.b   out5_4             ; while (p) {
  182. out5_3:     lsr.w   #1,D3               ;    p>>=1
  183.             dbeq    D1,out5_3           ;+
  184. out5_4:     add.w   D1,D1               ; 2*2
  185.             neg.w   D1                  ;
  186.             lea     p_freq,A0           ; p_freq
  187.             addq.w  #1,32(A0,D1.w)      ;+ p_freq[c]++
  188. out5_5:     move.w  d0,output_pos-pos(a6) ;sichern
  189.             rts
  190.  
  191. nout_5_1:            
  192.             move.b  D3,(A1)+            ;+ buf[output_pos++]=p
  193.             addq.w  #2,D0               ;+ output_pos++&++
  194.  ;           moveq   #8,D2              ; *TT -> move.w d3,...*
  195.             moveq   #7,D2              ; *TT -> move.w d3,...*
  196.  ;           tst.w   D1                  ;.W!!!!
  197.  ;           dbeq    D2,nout5_3           ;
  198.  ;           bra.b   nout5_4             ; while (p) {
  199. nout5_3:    lsr.b   #1,D1               ;    p>>=1
  200.             dbeq    D2,nout5_3           ;+
  201. nout5_4:    add.w   D2,D2               ; 2*2
  202.             neg.w   D2                  ;
  203.             lea     p_freq,A0           ; p_freq
  204.             addq.w  #1,32(A0,D2.w)      ;+ p_freq[c]++
  205.             move.w  d0,output_pos-pos(a6) ;sichern
  206.             rts
  207.  
  208.  
  209.  
  210.         ENDMOD
  211.  
  212.             align
  213.  
  214.         MODULE insert_node
  215.  
  216.         IMPORT avail
  217.         EXPORT insert_n
  218.  
  219.         TEXT
  220. insert_n:
  221. ;insert_node:                       ;
  222.             move.l position-pos(a6),A1 ;+
  223.             subq.w  #4,d7           ;+ if (matchl >= 4)
  224.             blt.b   inode7          ;
  225.             addq.w  #3,d7           ;+ matchl--
  226.             moveq   #1,D4           ;
  227.             add.w   d6,D4           ;
  228.             or.w    #$2000,D4       ; r=(matchpos+1)|DICSIZ
  229. ; --------------------------------------;
  230.             move.l  D4,D0           ;+  r (.l -> D0 upper = 0)
  231.             add.w   D0,D0           ;+  r * 2
  232.             move.w  0(A2,D0.l),D5   ;+  q=parent[r]
  233.             bne.b   inode1_         ;+ }
  234. inode1:     move.w  0(A4,D0.l),D4   ;   r=next[r]
  235.             move.w  D4,D0           ;   r
  236.             add.w   D0,D0           ;   r * 2
  237.             move.w  0(A2,D0.l),D5   ;   q=parent[r]
  238.             beq.b   inode1          ; }
  239. inode1_:    move.l  level(PC),A0    ;
  240.             cmp.b   0(A0,D5.w),d7   ;+   level[q] }
  241.             bhi.b   inode3_         ;+
  242. inode3:     move.w  D5,D4           ;   r = q
  243.             add.w   D5,D5           ;   q * 2
  244.             move.w  0(A2,D5.l),D5   ;   q=parent[q]
  245. ;            move.b  0(A0,D5.w),D0   ;   level[q]
  246. ;            cmp.b   D0,d7           ;+ }
  247.             cmp.b   0(A0,D5.w),D7   ;   level[q]
  248.             bls.b   inode3          ;+
  249. inode3_:     move.w  D5,D0           ; t = q
  250.             add.w   D0,D0           ;+ t * 2
  251.             move.w  0(A1,D0.l),D1   ;+  position[t]
  252.             bge.b   inode5_         ;+ while (position[t] < 0) {
  253.             move.w  (a6),d2         ;+ pos
  254. inode5:     move.w  d2,0(A1,D0.l) ;+    position[t] = pos
  255.             move.w  0(A2,D0.l),D0   ;   t=parent[t]
  256.             add.w   D0,D0           ;+ t * 2
  257.             move.w  0(A1,D0.l),D1   ;+  while(position[t]<0)
  258.             blt.b   inode5          ; }
  259. inode5_:    cmp.w   #$4000,D0       ; if (t < DICSIZ) {
  260.             bge.s   inode9          ;
  261.             move.w  (A6),D2         ;   pos
  262.             or.w    #$8000,D2       ;   pos | PERC_FLAG
  263.             move.w  D2,0(A1,D0.l)   ;+  position[t] = pos | PERC_FLAG
  264.             bra.b   inode9          ;
  265. ; --------------------------------------:
  266. inode7:     move.w  (A6),D0         ; pos
  267.             move.l text-pos(a6),A0      ;
  268.             moveq   #0,d5           ;
  269.             move.b  0(A0,D0.w),D5   ; q = text[pos]
  270.             add.w   #$2000,D5       ; + DICSIZE
  271.             moveq   #0,D4           ;+
  272.             move.b  1(A0,D0.w),d7   ; c = text[pos+1]
  273.             move.b  D7,D4           ;+
  274. ; --------------------------------------; beg child
  275.             lsl.w   #4,D4           ;
  276.             add.w   D5,D4           ;
  277.             add.w   #$4000,D4       ; r=HASH(q,c)
  278.             add.w   D4,D4           ;+ 2*r
  279.             move.w  D5,(A2)         ; parent[NIL]=q
  280. nchild1:    move.w  0(A4,D4.l),D4   ;+ r=next[r]
  281.             add.w   D4,D4           ;+ 2*r
  282.             cmp.w   0(A2,D4.l),D5   ; while (parent[r] != q)
  283.             bne.b   nchild1         ;
  284. ; --------------------------------------;
  285.             lsr.w   #1,D4
  286.             bne.b   inode8          ; if ((r=child(q,c)) == NIL)
  287. ; --------------------------------------;
  288.             move.w  (A6),D2         ; pos
  289. ;D4 ist 0!      moveq   #0,d4           ;d7 upper = 0?
  290.             move.b  d7,D4           ; c
  291. ; --------------------------------------; makechild
  292.             lsl.w   #4,D4           ; c<<DICBIT-9
  293.             add.w   d5,D4           ; p+c
  294.             add.w   #$4000,D4       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  295.             move.w  D4,D1           ; h
  296.             add.w   D4,D4           ;+ 2*h
  297.             move.w  0(A4,D4.l),D3   ; t=next[h]
  298.             move.w  D2,0(A4,D4.l)   ; next[h]=r
  299.             move.w  D2,D4           ; r
  300.             add.w   D4,D4           ;+ 2*r
  301.             move.w  D3,0(A4,D4.l)   ; next[r]=t
  302. ;           ext.l   D3              ; t?
  303.             add.w   D3,D3           ;+ 2*t
  304.             move.w  D2,0(A3,D3.l)   ; prev[t]=r
  305.             move.w  D1,0(A3,D4.l)   ; prev[r]=h
  306.             move.w  d5,0(A2,D4.l)   ; parent[r]=q
  307.             move.l childcount-pos(a6),A0    ;
  308.             addq.b  #1,0(A0,d5.w)   ; childcount[q]++
  309. ; --------------------------------------; makechild
  310.             moveq   #1,d7           ;+ matchl=1
  311.             rts                     ; return
  312. ; --------------------------------------;
  313. inode8:     moveq   #2,d7           ; matchl=2
  314. inode9:     cmp.w   #$2000,D4       ; if (r>DICSIZ)
  315.             blt.b   inode10         ;
  316.             move.w  #$0100,d2       ; j = MAXMATCH
  317.             move.w  D4,d6           ; matchpos=r
  318.             bra.b   inode11         ;
  319. inode10:    move.l level(PC),A0     ;
  320.             moveq   #0,d2           ;
  321.             move.b  0(A0,D4.w),d2   ; r=level[r]
  322.             move.w  D4,D0           ; r
  323.             add.w   D0,D0           ; r*2
  324. ;           move.l position-pos(a6),A1 ;
  325.             move.w  0(A1,D0.l),D1   ; position[r]
  326.             and.w   #$7FFF,D1       ; position[r] & ~PERC_FLAG
  327.             move.w  D1,d6           ; matchpos=position[r] & ~ PERC_FLAG
  328. inode11:    move.w  (A6),D0         ;+ pos
  329.             cmp.w   D0,D6           ;+
  330.             blt.b   inode12         ; if (matchpos>=pos)
  331.             subi.w  #$2000,d6       ; matchpos-=DICSIZE
  332. ; --------------------------------------;
  333. inode12:    add.w   d7,D0           ; pos+matchl
  334.             move.l text-pos(a6),A0 ; text
  335.             lea     0(a0,d0.w),a5
  336.             move.w  d6,D1           ; matchpos
  337.             add.w   d7,D1           ; matchpos+matchl
  338.             lea     0(a0,d1.l),a0   ; t2=text[matchpos+matchl]
  339.             move.w  d2,d0
  340.             sub.w   d7,d0
  341.             beq.b   inode14
  342.             subq.w  #1,d0
  343. inode13:    cmpm.b  (A5)+,(A0)+     ;
  344.             dbne    d0,inode13      ; matchl<j
  345.             bne     in_split
  346. ;               neg.w   d0
  347.             not.w   d0              ;
  348.             add.w   d2,d0
  349. ;               subq.w  #1,d0
  350.             move.w  d0,d7
  351. ; --------------------------------------;
  352. inode14:    cmp.w   #$0100,d7       ; if matchl>MAXMATCH
  353.             bge.b   inode17         ; break
  354. ; --------------------------------------;
  355. ;           move.w  D4,D0           ; r
  356.             move.w  D4,D5           ; q=r
  357. ;           add.w   D0,D0           ;+ 2*r
  358.             add.w   D4,D4           ;+ 2*r
  359. ;           move.l position-pos(a6),A0  ;
  360. ;               move.w  (A6),0(A0,D0.l) ; position[r]=pos
  361.             move.w  (A6),0(A1,D4.l) ; position[r]=pos
  362. ;           move.w  D4,D5           ; q=r
  363.             moveq   #0,d4           ;+
  364.             move.b  (A5),D4         ;+ *t1
  365. ; --------------------------------------; beg child
  366.             lsl.w   #4,D4           ;+
  367.             add.w   D5,D4           ;+
  368.             add.w   #$4000,D4       ;+ h=HASH(q,c)
  369.             add.w   D4,D4           ;+ 2*h
  370.             move.w  D5,(A2)         ; parent[NIL]=q
  371. nchild2:    move.w  0(A4,D4.l),D4   ;+ r=next[r]
  372.             add.w   D4,D4           ;+ 2*r
  373.             cmp.w   0(A2,D4.l),D5   ;+ while (parent[r] != NIL)
  374.             bne.b   nchild2         ;
  375. ; --------------------------------------; end child
  376.             lsr     #1,D4
  377.             bne.b   inode16         ; if ((r=child(q,*t1)) != NIL) {
  378.             move.w  (A6),D2         ;   pos
  379. ;D4 ist 0!      moveq   #0,d4
  380.             move.b  (A5),D4         ;   *t1
  381. ; --------------------------------------; makechild
  382.             lsl.w   #4,D4           ; c<<DICBIT-9
  383.             add.w   d5,D4           ; p+c
  384.             add.w   #$4000,D4       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  385.             move.w  D4,D1           ; h
  386.             add.w   D4,D4           ;+ 2*h
  387. ;;            moveq   #0,D3           ;+?
  388.             move.w  0(A4,D4.l),D3   ; t=next[h]
  389.             move.w  D2,0(A4,D4.l)   ; next[h]=r
  390.             move.w  D2,D4           ; r
  391.             add.w   D4,D4           ;+ 2*r
  392.             move.w  D3,0(A4,D4.l)   ; next[r]=t
  393.             add.w   D3,D3           ; 2*t
  394.             move.w  D2,0(A3,D3.l)   ; prev[t]=r
  395.             move.w  D1,0(A3,D4.l)   ; prev[r]=h
  396.             move.w  d5,0(A2,D4.l)   ; parent[r]=q
  397.             move.l childcount-pos(a6),A0    ;
  398.             addq.b  #1,0(A0,d5.w)   ; childcount[q]++
  399.             rts                     ;   return
  400. ; --------------------------------------;
  401. inode16:    addq.w  #1,d7           ; matchl++
  402.             bra     inode9          ; } /* for */
  403. ; --------------------------------------;
  404. inode17:    move.w  (a6),d3
  405.             move.w  D4,D0           ; r
  406.             add.w   D0,D0           ;+ 2*r
  407.             move.w  0(A3,D0.l),D1   ; t = prev[r]
  408.             move.w  d3,D2           ; pos
  409.             add.w   D2,D2           ;+ 2*pos
  410.             move.w  D1,0(a3,D2.w)   ; prev[pos]=t
  411.             add.w   D1,D1           ;+ 2*t
  412.             move.w  d3,0(A4,D1.l)   ; next[r] = pos
  413.             move.w  0(A4,D0.l),D1   ; t=next[r]
  414.             move.w  D1,0(A4,D2.l)   ; next[pos]=t
  415.             add.w   D1,D1           ;+ 2*t
  416.             move.w  d3,0(a3,D1.l)   ; prev[t] = pos
  417.             move.w  D5,0(A2,D2.l)   ; parent[pos]=q
  418.             clr.w   0(A2,D0.l)      ; parent[r] = NIL
  419.             move.w  d3,0(A4,D0.l)   ; next[r]=pos
  420.             rts                     ;
  421.  
  422.     ENDMOD
  423.  
  424.             align
  425.  
  426.     MODULE in_split
  427.  
  428. ;in_split:
  429.             not.w   d0              ;+
  430.             add.w   d2,d0
  431.             move.w  d0,d7           ;matchlen=matchl;
  432.             move.w  D4,D1           ;   split(r)
  433. ; --------------------------------------; split
  434.             movem.l (a6),D3/A0/A5   ; new=avail + pos + &childcount
  435.                                     ; + &text
  436.             move.w  D3,D2           ; new
  437.             add.w   D2,D2           ;+ new * 2
  438.             move.w  0(A4,D2.l),avail-pos(a6) ; avail=next[new]
  439.             move.b  #2,0(A0,D3.w)   ;+ childcount[new] = 0+1+1
  440.             add.w   D1,D1           ;+ old * 2
  441.             move.w  0(A3,D1.l),D0   ; t = prev[old]
  442.             move.w  D0,0(A3,D2.l)   ; prev[new] = t
  443.             add.w   D0,D0           ;+ t * 2
  444.             move.w  D3,0(A4,D0.l)   ; next[t] = new
  445.             move.w  0(A4,D1.l),D0   ; t=next[old]
  446.             move.w  D0,0(A4,D2.l)   ; next[new] = t
  447.             add.w   D0,D0           ;+ t * 2
  448.             move.w  D3,0(A3,D0.l)   ; prev[t] = new
  449.             move.w  0(A2,D1.l),0(A2,D2.l) ; parent[new] = parent[old]
  450.             move.w  (a6),0(A1,D2.l) ; positon[new]=pos
  451.             ;(a6) steht in d3 high word ....
  452.             move.l  level(PC),a1    ; ab hier nicht mehr position
  453.             move.b  d7,0(A1,d3.w)   ; level[new]=matchlen
  454. ; makechil(new,text[matchpos+matchlen],old)
  455.             move.w  d6,D0           ;
  456.             add.w   d7,D0           ;
  457.             moveq   #0,d2           ;
  458.             move.b  0(A5,D0.w),D2   ;
  459. ; --------------------------------------;
  460.             lsl.w   #4,D2           ; c<<DICBIT-9
  461.             add.w   D3,D2           ; p+c
  462.             add.w   #$4000,D2       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  463.             move.w  D2,D0           ; h
  464.             add.w   D2,D2           ;+ 2*h
  465.             move.w  0(A4,D2.l),d5   ; t=next[h]
  466.             move.w  D4,0(A4,D2.l)   ; next[h]=r
  467.             move.w  d5,0(A4,D1.l)   ; next[r]=t
  468.             add.w   d5,d5           ;+ 2*t
  469.             move.w  D4,0(A3,d5.l)   ; prev[t]=r
  470.             move.w  D0,0(A3,D1.l)   ; prev[r]=h
  471.             move.w  D3,0(A2,D1.l)   ; parent[r]=q
  472. ; makechild(new,text[pos+matchlen],pos)
  473.             swap    d3
  474.             move.w  d3,D2
  475.             add.w   d7,D3
  476.             moveq   #0,d4
  477.             move.b  0(A5,D3.w),D4   ;+ text[pos+matchlen]
  478.             swap    d3
  479. ; --------------------------------------; makechild
  480.             lsl.w   #4,D4           ; c<<DICBIT-9
  481.             add.w   D3,D4           ; p+c
  482.             add.w   #$4000,D4       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  483.             move.w  D4,D1           ; h
  484.             add.w   D4,D4           ;+ 2*h
  485.             move.w  0(A4,D4.l),D0   ; t=next[h]
  486.             move.w  D2,0(A4,D4.l)   ; next[h]=r
  487.             move.w  D2,D4           ; r
  488.             add.w   D4,D4           ;+ 2*r
  489.             move.w  d0,0(A4,D4.l)   ; next[r]=t
  490.             add.w   d0,d0           ;+ 2*t
  491.             move.w  D2,0(A3,d0.l)   ; prev[t]=r
  492.             move.w  D1,0(A3,D4.l)   ; prev[r]=h
  493.             move.w  D3,0(A2,D4.l)   ; parent[r]=q
  494.             moveq    #0,D3
  495.             rts
  496.     ENDMOD
  497.  
  498.             align
  499.  
  500.     MODULE get_next_match
  501.  
  502.         EXPORT gnext1,get_next
  503.  
  504.         IMPORT my_cnt,st_save
  505.  
  506.     TEXT
  507.  
  508. get_next:
  509. ;get_next_match:
  510.             subq.w  #1,remainder-pos(a6)
  511. ;           addq.w  #1,(a6)
  512. ;           cmpi.w  #$4000,(a6)
  513.             cmpi.w  #$3fff,(a6)
  514. ;               bne.b   gnext1
  515.             beq     get_n_m_1
  516.             addq.w  #1,(a6)
  517. ;gnext1:     movem.w D4-d5,-(sp)
  518. gnext1:     move.w D4,-(sp)
  519. ;GLOBAL         move.l parent-pos(a6),a2
  520. ;GLOBAL         move.l next-pos(a6),a4
  521. ;GLOBAL         move.l prev-pos(a6),a3
  522. ;eventuell D6 const #$2000
  523. ;delete_node:
  524. ;;;            moveq   #0,d2           ;+
  525.             move.w  (a6),d2         ; d2=pos
  526. ;               move.w  d2,D1           ; pos
  527.             move.l  d2,D1           ;+ pos
  528.             add.w   D1,D1           ; 2*pos
  529. ;?              move.w  0(A2,D1.l),D0   ; if (parent[pos] == NIL)
  530. ;;;            moveq   #0,d3           ;+
  531.             move.w  0(A2,D1.l),D3   ;+ if ((r=parent[pos]) == NIL)
  532.             beq.b   dnode9_         ;    return
  533. ;           moveq   #0,d3           ;+
  534.             move.w  0(A3,D1.w),D5   ; r' = prev[pos]
  535. ;           move.w  0(A3,D1.w),D3   ; r = prev[pos]
  536.             move.w  0(A4,D1.w),D4   ; s = next[pos]
  537. ;           move.l  D3,D0           ;+ r
  538.             move.l  D5,D0           ;+ r'
  539.             add.w   D0,D0           ; 2 * r
  540.             move.w  D4,0(A4,D0.l)   ; next[r]=s
  541. ;           move.w  D4,D0           ; s
  542. ;           add.w   D0,D0           ;+ s * 2
  543.             add.w   D4,D4           ;+ s * 2
  544. ;           move.w  D3,0(A3,D0.w)   ;+ prev[s] = r
  545.             move.w  D5,0(A3,D4.w)   ;+ prev[s] = r'
  546. ;           move.w  0(A2,D1.w),D3   ;+ r = parent[pos]
  547. ;               clr.w   0(A2,D1.l)      ; parent[pos] = NIL
  548.             clr.w   0(A2,D1.l)      ; parent[pos] = NIL
  549.             cmp.w   #$2000,D3       ; if (r >= DICSIZ)
  550. ;           bge     dnode9          ;
  551.             blt.b   dnodea_         ;
  552. dnode9_:
  553. ; **************************************************************************
  554.             bsr     insert_node
  555. ;            movem.w (sp)+,d4-d5
  556.             move.w (sp)+,d4
  557.             rts
  558. dnodea_:    move.l childcount-pos(a6),A1    ;   ||
  559.             adda.l  D3,A1           ;+ (long ist schneller!)
  560.             subq.b  #1,(A1)         ;+  --childcount[r]
  561.             cmpi.b  #1,(A1)         ;+  > 1)
  562.             bhi.b   dnode9_         ;     return
  563.             move.l position-pos(a6),A1  ; position
  564.             move.w  D3,D1           ; r
  565.             add.w   D1,D1           ;+ r * 2
  566.             move.w  0(A1,D1.w),D5   ; t=position[r]
  567.             and.w   #$7FFF,D5       ;        & ~PERC_FLAG
  568.             cmp.w   d2,D5           ; if (t>=pos)
  569.             blt.b   dnode1          ;
  570.             sub.w   #$2000,D5       ;   t-=DICSIZ
  571. ;---------------------------------------;
  572. dnode1:     move.w  D5,D4           ; s = t
  573.             move.w  d5,a0
  574.             move.w  0(A2,D1.l),D0   ; q = parent[r]
  575.             add.w   d0,d0           ; q*2
  576.             move.w  0(A1,D0.l),d5   ;+  u=position[q]
  577.             bclr    #15,D5          ;+
  578.             beq.b   dnode5_
  579. dnode2:     cmp.w   d2,d5           ;   if (u>=pos)
  580.             blt.b   dnode3          ;
  581.             sub.w   #$2000,d5       ;       u-=DICSIZ
  582. dnode3:     cmp.w   d5,D4           ;   if (u>=s)
  583.             bge.b   dnode4          ;
  584.             move.w  d5,D4           ;       s=u
  585. dnode4:     move.w  D4,D1           ;   s
  586.             or.w    #$2000,D1       ;   |DICSIZ
  587.             move.w  D1,0(A1,D0.l)   ;   position[q] = s | DICSIZ
  588.             move.w  0(A2,D0.l),D0   ;   q=parent[q]
  589.             add.w   d0,d0           ;   q*2
  590. ;dnode5:
  591.             move.w  0(A1,D0.l),d5   ;   u=position[q]
  592. ;               move.w  d5,D1           ;   u
  593. ;               and.w   #$8000,D1       ;   parent[r] & PERC_FLAG
  594.             bclr    #15,D5          ;+
  595.             bne.b   dnode2          ; }
  596. dnode5_:
  597. ;   end_while   ------------------------;
  598.             cmp.w   #$4000,D0       ; if (q<DICISZ}
  599.             bge.b   dnode8          ; {
  600.             cmp.w   d2,d5           ;   if (u>=pos)
  601.             blt.b   dnode6          ;
  602.             sub.w   #$2000,d5       ;        u-=DICSIZ
  603. dnode6:     cmp.w   d5,D4           ;   if (u>s)
  604.             bge.b   dnode7          ;
  605.             move.w  d5,D4           ;     s=u
  606. dnode7:     or.w    #$A000,D4       ;   s|DICSIZ|PERC_FLAG
  607.             move.w  D4,0(A1,D0.l)   ;   position[q]=s|DICSIZ|PERC_FLAG
  608. ;---------------------------------------;
  609. dnode8:     move.l level(PC),A1     ; level
  610.             moveq   #0,D0           ;+
  611.             move.b  0(A1,D3.w),D0   ; level[r]
  612.             add.w   a0,D0           ; level[r]+t
  613.             move.l text-pos(a6),A1 ; text
  614.             moveq   #0,d4           ;+
  615. ;               move.b  0(A1,D0.w),D2   ; text[level[r]+t]
  616.             move.b  0(A1,D0.w),D4   ; text[level[r]+t]
  617. ; --------------------------------------; beg child
  618. ;               and.l   #$ff,d2         ;obere 16 bit immer = 0 !
  619. ;               moveq   #0,D2           ;
  620. ;                move.b  D1,D2          ;
  621. ;                lsl.w   #4,D2          ;
  622.             lsl.w   #4,D4           ;+
  623. ;                add.w   D3,D2          ;
  624.             add.w   D3,D4           ;+
  625. ;                add.w   #$4000,D2       ; h=HASH(q,c)
  626.             add.w   #$4000,D4       ;+ h=HASH(q,c)
  627.             add.w   D4,D4           ;+ 2*h
  628.             move.w  d3,(A2)         ; parent[NIL]=q
  629. dchild1:    move.w  0(A4,D4.l),D4   ;+ r=next[r]
  630.             add.w   D4,D4           ; 2*r
  631.             cmp.w   0(A2,D4.l),D3   ; while (parent[r] != NIL)
  632.             bne.b   dchild1          ;
  633.             move.w  D4,D0           ;+ s*2
  634.             lsr.w   #1,D4
  635. ; --------------------------------------; end child
  636.             move.w  0(A3,D0.w),D5   ; t=prev[s]
  637.             move.w  0(A4,D0.w),D2   ; u=next[s]
  638.             move.w  D5,D1           ; t
  639.             add.w   D1,D1           ; t * 2
  640.             move.w  D2,0(A4,D1.l)   ; next[t] = u
  641.             add.w   D2,D2           ; u * 2
  642.             move.w  D5,0(A3,D2.w)   ; prev[u] = t
  643.             move.w  D3,D2           ; r
  644.             add.w   D2,D2           ; r * 2
  645.             move.w  0(A3,D2.w),D5   ;+ t = prev[r]
  646.             move.w  D5,0(A3,D0.w)   ;+ prev[s] = t
  647.             add.w   D5,D5           ; t * 2
  648.             move.w  D4,0(A4,D5.l)   ; next[t] = s
  649.             move.w  0(A4,D2.l),D5   ; t=next[r]
  650.             move.w  D5,0(A4,D0.l)   ;+ next[s]=t
  651.             add.w   D5,D5           ; t * 2
  652.             move.w  D4,0(A3,D5.w)   ; prev[t]=s
  653.             move.w  0(A2,D2.l),0(A2,D0.l) ; parent[s]=parent[r]
  654.             clr.w   0(A2,D2.l)      ; parent[r]=NIL
  655.             move.w  avail-pos(a6),0(A4,D2.l) ; next[r]=avail
  656.             move.w  D3,avail-pos(a6) ; avail=r
  657. dnode9:
  658. ; **************************************************************************
  659.             bsr     insert_node
  660. ;            movem.w (sp)+,d4-d5
  661.             move.w (sp)+,d4
  662.             rts
  663. get_n_m_1:
  664. ;               move.l  #$2100,D0
  665.             move.l text-pos(a6),A0
  666.             lea     $2000(A0),A0
  667. ;               lea     $2000(A0),A1
  668. ;++++++++++++++++
  669.             movem.l D1-D7/A2-A6,-(a7)       ;regs für gnext1 mit?
  670.             move.l  A7,st_save ;
  671.             move    #7,my_cnt
  672. nxt_cpy:
  673.         REPT 20
  674.             movem.l (a0)+,D0-D7/A1-A7
  675.             movem.l D0-D7/A1-A7,-$203c(a0)
  676.         ENDM
  677.             subq.w  #1,my_cnt
  678.             bne     nxt_cpy
  679.             movem.l (a0)+,D0-D7/A1-A4
  680.             movem.l D0-D7/A1-A4,-$2030(a0)
  681.             move.l  st_save(PC),A7
  682.             movem.l (a7)+,D1-D7/A2-A6
  683. ;               bsr     memcpy
  684. ;++++++++++++++++++
  685.             move.l infile(PC),A1
  686.             move.w  #$2000,D0
  687.             move.l text-pos(a6),A0
  688.             lea     $2100(A0),A0
  689.             bsr     fread_crc
  690.             add.w   D0,remainder-pos(a6)
  691.             move.w  #$2000,pos-pos(A6)
  692.             ext.l   d0
  693.             add.l   d0,printcount-pos(a6)
  694.             cmp.w   #$2000,d0
  695.             blt.s   ind1
  696. proc_ind1:  move.l  blocksize(pc),d0
  697.             cmp.l   printcount(pc),d0
  698.             bgt.s   gnext1_
  699.             sub.l   d0,printcount-pos(a6)
  700. ind1:       bsr     ProcInd
  701.             bra.s   proc_ind1
  702.  
  703. gnext1_:
  704.             moveq    #0,D0
  705.             moveq    #0,D1
  706.             moveq    #0,D2
  707.             bra        gnext1
  708.  
  709.     ENDMOD
  710.  
  711.             align
  712.  
  713.     MODULE init_encode5
  714.  
  715.         EXPORT init_en
  716.  
  717. init_en:
  718. ;init_encode5:
  719. ;            bsr     allocate_memory
  720. ;               bsr     init_slide
  721.             movem.l D2-D7/A2-A6,-(A7)
  722.             moveq   #0,D0
  723.             lea     pos(pc),A6
  724.             move.w  d0,output_pos-pos(a6)   ;hier im Modul
  725.             move.w  d0,output_mask-pos(a6)  ;da Adressierung schneller
  726.             move.l  d0,printcount-pos(a6)
  727.             move.w  #1,avail-pos(a6)
  728.             moveq   #0,D1
  729.             moveq   #0,D2
  730.             moveq   #0,D3
  731.             moveq   #0,D4
  732.             moveq   #0,D5
  733.             moveq   #0,D6
  734.             moveq   #0,D7
  735.             move.l  D0,A0
  736.             move.l  D0,A1
  737.             move.l  D0,A2
  738.             move.l  D0,A3
  739.             move.l  D0,A4
  740.             move.l  D0,A5
  741.             move.l  position(PC),A6
  742.             lea     ($2100*2)(A6),A6
  743.         REPT 9
  744.             movem.l D0-D7/A0-A5,-(A6)  ;
  745.         ENDM
  746.             movem.l D0-D1,-(A6)       ; (9*14+4)*2=256
  747.             move.l  parent(PC),A6
  748.             adda.l  #(($2000*2)*2),A6
  749.             move.w  #78-1,D7
  750. qdel_1:
  751.         REPT 4
  752.             movem.l D0-D6/A0-A5,-(A6)  ;
  753.         ENDM
  754.             dbra    D7,qdel_1
  755.         REPT 3
  756.             movem.l D0-D6/A0-A5,-(A6)  ;
  757.         ENDM
  758.             move.w  D0,-(A6)            ; (315*13+1)*2=$2000
  759.             move.l  next(PC),A6
  760.             adda.l  #$70F0*2,A6         ; 25056 Bytes = 0x61E0
  761.             move.w  #60-1,D7
  762. qdel_2:
  763.         REPT 8
  764.             movem.l D0-D6/A0-A5,-(A6)  ;
  765.         ENDM
  766.             dbra    D7,qdel_2
  767.             movem.l D0-D6/A0-A5,-(A6)  ;
  768.             movem.l D0-D6/A0-A3,-(A6)  ; (481*13+11)*4= 0x6130
  769.             move.l  #0x00020002,D2
  770.             move.l  d2,D0
  771.             addq    #1,d0               ;d0=0x00020003
  772.             move.l  next(PC),A6
  773.             lea     2(a6),a6
  774.             move.w  #1023-1,d1
  775. islide6:
  776.         REPT 4
  777.             move.l  D0,(a6)+
  778.             add.l   D2,D0
  779.         ENDM
  780.             dbra    d1,islide6
  781.         REPT 3
  782.             move.l  D0,(a6)+
  783.             add.l   D2,D0
  784.         ENDM
  785.                                         ;1023*4*2+3*2=
  786.             move.w  d3,(a6)             ;next[DICSIZ - 1] = NIL;
  787.             move.l  #$01010101,D0       ;Wir brauchen einsen
  788.             move.l  d0,d1
  789.             move.l  d0,d2
  790.             move.l  d0,d3
  791.             move.l  d0,d4
  792.             move.l  d0,d5
  793.             move.l  d0,d6
  794.             move.l  d0,d7
  795.             move.l  d0,A0
  796.             move.l  d0,a1
  797.             move.l  d0,a2
  798.             move.l  d0,a3
  799.             move.l  d0,a4
  800.             move.l  d0,a5
  801.             move.l  level(PC),a6
  802.             lea     $2100(a6),a6
  803.             movem.l D0-D7/A0-A5,-(A6)  ;
  804.             movem.l D0-D7/A0-A5,-(A6)  ;
  805.             movem.l D0-D7/A0-A5,-(A6)  ;
  806.             movem.l D0-D7/A0-A5,-(A6)  ;
  807.             movem.l D0-D7,-(A6)     ;   (4*14+8)*4=256
  808.             movem.l (A7)+,D2-D7/A2-A6
  809.             bsr     start_huf
  810.             rts
  811.  
  812.     ENDMOD
  813.  
  814.     DATA
  815.  
  816.     align.l
  817.  
  818. level:        dc.l    0
  819. position:   dc.l    0
  820. next:       dc.l    0
  821. prev:       dc.l    0
  822. parent:     dc.l    0
  823. pos:        dc.w    0           ;               !
  824. avail:      dc.w    0           ;               !
  825. childcount: dc.l    0           ; Reihenfolge   !
  826. text:       dc.l    0           ;               !
  827. remainder:  dc.l    0
  828. cpos:       dc.w    0
  829.     align.l
  830. printcount: dc.l    0
  831. ;+++++++++++++++++++++
  832. output_pos: dc.w    0
  833.     align.l
  834. output_mask:dc.w    0
  835.     align.l
  836. l_mpos:        dc.w    0
  837.     align.l
  838. st_save:    dc.l    0       ;Zähler und Save
  839. my_cnt:     dc.w    0      ;für Copy
  840.     align.l
  841.  
  842.     END
  843.